import redis
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
#3.0
from flask_wtf.csrf import CSRFProtect
#4.0
from flask_session import Session
#5.0
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand


class Config(object):
    SQLAlCHEMY_DATABASE_URI = 'mysql://root:mysql@localhost/pyinfo'
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    #2.1配置Redis
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = 6379

    #4.0生成随机数
    SECRET_KET = '1egY3wXpn8FO/cUlP+s+aBB1D1Ct38sqrGdHDAFmUG1qELJzXxu5d4zZTvxAbj1L/0Hw7EJVUxgmvNy/oYs='
    #4.2配置flask-session扩展
    SESSION_TYRE = 'redis'#设置同步信息
    SESSION_REDIS = redis.StrictRedis(host=REDIS_HOST,port=REDIS_PORT)
    SESSION_USE_SIGNER = True #开启签名,保证数据安全
    PERMANENT_SESSION_LIFETIME = 86400*7 #配置国企时间
    #5.0
    DEBUG = True
app = Flask(__name__)

app.config.from_object(Config)

db = SQLAlchemy(app)
#2.0
redis_store = redis.StrictRedis(host=Config.REDIS_HOST,port=Config.REDIS_PORT)

#3.1开启保护_开启csrf_tocken对比机制
CSRFProtect(app)
#4.1设置Flask-SessionK扩展
# 将存在浏览器的cookie中的session数据,同步到服务器指定地址中(redis)
Session(app)

#5.0c创建Manager
manager = Manager(app)

#5.2创建迁移对象
Migrate(app,db)
#5.3Manager绑定迁移命令
manager.add_command('db',MigrateCommand)

@app.route("/")
def index():
    return 'hello'
